# Missing data

# Load the data
data(sleep, package = "VIM")

# List the rows that do not have missing value
sleep[complete.cases(sleep), ]

# List the rows that have one or more missing values
sleep[!complete.cases(sleep), ]

sum(is.na(sleep$Dream))
mean(is.na(sleep$Dream))
mean(!complete.cases(sleep))

## mice

library(mice)

data(sleep, package = "VIM")
md.pattern(sleep)

library(VIM)

aggr(sleep, prop = F, numbers = T)

matrixplot(sleep)

marginplot(sleep[c("Gest", "Dream")], pch = c(20),
           col = c("darkgray", "red", "blue"))

x <- as.data.frame(abs(is.na(sleep)))
head(sleep, n = 5)
head(x, n = 5)

y <- x[which(sd(x) > 0), ]




